/******************************************************************************
 * (C) Copyright 2020 Atech-Automotive
 * FILE NAME:    APP_Can_Types.h
 * DESCRIPTION:
 * 
 * DATE BEGUN:   2020/09/10
 * BY:           YONG.DING
 * PRODUCT NAME:
 * APPLICATION:
 * TARGET H/W:
 * DOC REF:
 *****************************************************************************
 */                 

#ifndef _APP_SCITYPE_H_
#define _APP_SCITYPE_H_

/*****************************************************************************
** #include
*****************************************************************************/
#include"System.h"


/*****************************************************************************
** #define
*****************************************************************************/
#define SCI_PERIOD_2S              200  /*    2s in 10ms ticks */
#define SCI_PERIOD_1S              100  /*    1s in 10ms ticks */
#define SCI_PERIOD_500MS            50  /* 500ms in 10ms ticks */
#define SCI_PERIOD_200MS            20  /* 200ms in 10ms ticks */
#define SCI_PERIOD_100MS            10  /* 100ms in 10ms ticks */
#define SCI_PERIOD_50MS              5  /* 50ms in 10ms ticks */
#define SCI_PERIOD_20MS              2  /*  20ms in 10ms ticks */
#define SCI_PERIOD_10MS              1  /*  10ms in 10ms ticks */
#define SCI_TIMEOUT_RETRY_CN		 3

#define RX_SHORT_MSG_MAX_LEN 8
#define RX_LONG_MSG_MAX_LEN 16
#define TX_SHORT_MSG_MAX_LEN 8
#define TX_LONG_MSG_MAX_LEN 16
/*****************************************************************************
**  typedef
*****************************************************************************/

/***************************** msg type ***************************************/
/*
 * sci message type,
 * include normal,network management,diagnose
 */
typedef enum
{
    SCI_R_CONFIR_MSG = 0,
    SCI_CONTENT_MSG
}SCI_MSG_RCV_TYPE_E;

/*
 * sci message send type,
 * include cycle, event, cycle&&event
 */
typedef enum
{
    SCI_CYCLE = 0,
    SCI_EVENT,
    SCI_CE
}SCI_MSG_SEND_TYPE_E;

/*
 * net module power type
 */
//typedef enum
//{
//	POWER_30 = 0,
//	POWER_15
//}NODE_POWER_TYPE_E;

/*
 * sci message tx struct
 */
typedef struct
{
            BOOL              Enable;     /* control the message active or inactive*/
    const   UINT8                Id;         /* sci message identifier.      range:0x000~0xFF*/
			BOOL				Sub_Id_exist;/* TRUE IS EXIST ,FALSE IS NOT EXIST*/
    const   UINT8                Sub_Id;         /* sci message sub identifier.      range:0x000~0xFF*/			
            UINT8                Length;     /* sci message data length.     range:0~8*/
//    const   SCI_MSG_TYPE_E      Type;       /* sci message type.            range:normal,network management,diagnose*/
    const   SCI_MSG_SEND_TYPE_E SendType;   /* sci message send type.       range:cycle(C), event(E), cycle&event(CE)*/
            BOOL              Trigger;    /* trigger the msg send,if msg SendType is E or CE*/
    const   UINT16               CycleTime;  /* cycle msg,send cycle time*/
            UINT16               CTimer; /* timer for CycleTime*/
    const   UINT16               NobackTime;  /* event msg no feedback overtime */
            UINT16               NobackTimer; /* timer for TriTime */			
	const   UINT16               NobackRetry_cn_max;  /* event msg no feedback overtime */
			UINT8                NobackRetry_cn; /*Number of repeat when no feedback overtime */			
            UINT8                Data[TX_SHORT_MSG_MAX_LEN];/*sci data, bit 7 of data[0] transmitted first */  
}SCI_TX_MSG_S;

typedef struct
{
            BOOL              Enable;     /* control the message active or inactive*/
    const   UINT8                Id;         /* sci message identifier.      range:0x000~0xFF*/
			BOOL				Sub_Id_exist;/* TRUE IS EXIST ,FALSE IS NOT EXIST*/
    const   UINT8                Sub_Id;         /* sci message sub identifier.      range:0x000~0xFF*/			
            UINT8                Length;     /* sci message data length.     range:0~16*/
//    const   SCI_MSG_TYPE_E      Type;       /* sci message type.            range:normal,network management,diagnose*/
    const   SCI_MSG_SEND_TYPE_E SendType;   /* sci message send type.       range:cycle(C), event(E), cycle&event(CE)*/
            BOOL              Trigger;    /* trigger the msg send,if msg SendType is E or CE*/
    const   UINT16               CycleTime;  /* cycle msg,send cycle time*/
            UINT16               CTimer; /* timer for CycleTime*/
	const   UINT16               NobackTime;  /* event msg no feedback overtime */
            UINT16               NobackTimer; /* timer for TriTime */			
	const   UINT16               NobackRetry_cn_max;  /* event msg no feedback overtime */
			UINT8                NobackRetry_cn; /*Number of repeat when no feedback overtime */	
            UINT8                Data[TX_LONG_MSG_MAX_LEN];/*sci data, bit 7 of data[0] transmitted first */ 
}SCI_TX_LONG_MSG_S;
/*
 * sci message rx struct
 */
typedef struct
{
            BOOL              Enable;     /* control the message active or inactive*/
    const   UINT8                Id;         /* sci message identifier.      range:0x000~0xFF*/
			BOOL				Sub_Id_exist;/* TRUE IS EXIST ,FALSE IS NOT EXIST*/
    const   UINT8                Sub_Id;         /* sci message sub identifier.      range:0x000~0xFF*/			
            UINT8                Length;     /* sci message data length.     range:0~8*/
    const   SCI_MSG_RCV_TYPE_E  Type;       /* sci message type.            range:Receive confirmation message,content message*/
    const   SCI_MSG_SEND_TYPE_E SendType;   /* sci message send type.       range:cycle(C), event(E), cycle&event(CE)*/
    const   UINT16               CycleTime;  /* cycle msg,send cycle time*/
    const   UINT16               CycleTimeOut;/*timeout time to cycle msg*/
            UINT16               CTimer; /* timer for CycleTimeOut*/
//    const   NODE_POWER_TYPE_E   PowerType;  /* net module power type*/
            BOOL              Error;      /*it's true if the msg timeout*/
            BOOL              UpdataState;/*it's true if receive the msg*/
			BOOL              Waite_Feedback_Flag;/*it's true if have  the EVENT msg to wait*/
            UINT8                Data[RX_SHORT_MSG_MAX_LEN];/* sci data, bit 7 of data[0] transmitted first */
    const   UINT8                InitData[RX_SHORT_MSG_MAX_LEN];/*sci init data*/
//    const   UINT8                InvalidData[RX_SHORT_MSG_MAX_LEN];/*sci invalid data*/    
}SCI_RX_MSG_S;

typedef struct
{
            BOOL              Enable;     /* control the message active or inactive*/
    const   UINT8                Id;         /* sci message identifier.      range:0x000~0xFF*/
			BOOL				Sub_Id_exist;/* TRUE IS EXIST ,FALSE IS NOT EXIST*/
    const   UINT8                Sub_Id;         /* sci message sub identifier.      range:0x000~0xFF*/			
            UINT8                Length;     /* sci message data length.     range:0~8*/
    const   SCI_MSG_RCV_TYPE_E  Type;       /* sci message type.            range:Receive confirmation message,content message*/
    const   SCI_MSG_SEND_TYPE_E SendType;   /* sci message send type.       range:cycle(C), event(E), cycle&event(CE)*/
    const   UINT16               CycleTime;  /* cycle msg,send cycle time*/
    const   UINT16               CycleTimeOut;/*timeout time to cycle msg*/
            UINT16               CTimer; /* timer for CycleTimeOut*/
//    const   NODE_POWER_TYPE_E   PowerType;  /* net module power type*/
            BOOL              Error;      /*it's true if the msg timeout*/
            BOOL              UpdataState;/*it's true if receive the msg*/
			BOOL              Waite_Feedback_Flag;/*it's true if have  the EVENT msg to wait*/
            UINT8                Data[RX_LONG_MSG_MAX_LEN];/* sci data, bit 7 of data[0] transmitted first */
    const   UINT8                InitData[RX_LONG_MSG_MAX_LEN];/*sci init data*/
//    const   UINT8                InvalidData[RX_SHORT_MSG_MAX_LEN];/*sci invalid data*/      
}SCI_RX_LONG_MSG_S;
/***************************** driver *****************************************/
/*
 * sci message base struct
 */
typedef struct {
    UINT32 u32_msgId;
    UINT8  u8_dlc;
    UINT8  u8_data[8];
}DRV_SCI_MSG_S; 

/*
 * sci frame type
 */
 typedef enum
{    
    SCI_SHORT_MSG = 0,
    SCI_LONG_MSG,
	SCI_FAR_MSG,
}SCI_FRAME_TYPE_E;


/*
 * interrupt CMD
 */
//typedef enum{
//    RX_INT = 0,
//    TX_INT,
//    WAKEUP_INT,
//    ERROR_INT,
//    OVR_INT
//}SCI_INT_CONGIF_CMD_E;

/****************************************************************************/

#endif	//_APP_SCI_TYPES_H_

/*****************************************************************************
** End File
*****************************************************************************/

